<template>
	<div class="maxBox">
		<!-- 其他功能 -->
		<!-- 设置 -->
		<div class="zhezhao" id="zhezhao" v-if="showSet" @click="showSet = false"></div>
		<div class="setArr" v-if="showSet">
			<button @click="showNai = true" type="primary">
				添加牛奶品种
			</button>
			<button @click="goAdmin('nai')">
				查看牛奶品种列表
			</button>
			<button v-if="userType == '1' || userType == '2'" @click="showAddPhone = true" type="primary">
				添加用户
			</button>
			<button v-if="userType == '1' || userType == '2'" @click="goAdmin('userPhone')">
				查看用户列表
			</button>
			<button @click="showAddarea = true" type="primary">
				添加地区
			</button>
			<button @click="goAdmin('area')">
				查看地区列表
			</button>
		</div>
		<!-- 新增牛奶 管理员显示 -->
		<div class="zhezhao" id="zhezhao" v-if="showNai" @click="showNai = false"></div>
		<div class="jiaBox" v-if="showNai">
			<input type="text" placeholder="请输入牛奶名称" v-model="phone" />
			<button @click="addNai">添加品种</button>
		</div>

		<!-- 添加地区 -->
		<div class="zhezhao" id="zhezhao" v-if="showAddarea" @click="showAddarea = false"></div>
		<div class="jiaBox" v-if="showAddarea">
			<input type="text" placeholder="请输入地区" v-model="phone" />
			<button @click="addArea">添加地区</button>
		</div>

		<!-- 管理员新增 -->
		<div class="zhezhao" id="zhezhao" v-if="showAddPhone" @click="showAddPhone = false"></div>
		<div class="jiaBox" v-if="showAddPhone">
			<input type="text" placeholder="请输入管理员账号" v-model="phone" />
			<button @click="addAdmin">添加管理</button>
		</div>

		<!-- 报数 -->
		<div class="zhezhao" id="zhezhao" v-if="statistics" @click="statistics = false"></div>
		<div class="jiaBox" v-if="statistics">
			<ul class="painai">
				<li><span>品种</span><span>数量</span></li>
				<li v-for="item in statisticsArr">
					<span>{{ item.name }}</span> <span>{{ item.number }}</span>
				</li>
				<li>
					<span>总数</span><span>{{ sum }}</span>
				</li>
			</ul>
		</div>

		<!-- 自动排序 -->
		<div class="zhezhao" id="zhezhao" v-if="ssortShow" @click="ssortShow = false"></div>
		<div class="jiaBox" style="display: block;padding: 10px;box-sizing: border-box; " v-if="ssortShow">
			<div>
				<span @click="quickness()">点我---急速快排</span>
				<span>总数：{{count}}</span>
			</div>
			<div style="width: 100%;height: 100%;display: flex;flex-wrap: wrap;justify-content: space-between;">
				<span
					style="width: 18%; height: 25px; line-height: 30px; text-align: center; background-color: #1aad19;color: #fff; padding: 3px 0 ;margin: 5px 0 ;"
					v-for="(item, index) in sort" :key="index">{{ item.name }}:{{ item.number }}</span>

			</div>
		</div>
		<!-- 其他功能 ------------------------ -->
		<!-- <div class="user">尊敬的：{{user == "16692381725" ? user + '管理员' : user}} 您好 <span style="color: blue;"
				@click="anew">重新登录</span>
		</div> -->
		<div class="user">
			<div style="width: 3rem;height: 3rem;border-radius: 50%;overflow: hidden;background-color: #eee;">
				<img src="../../static/012_快递员.svg" style="width: 100%;height: 100%;" alt="" />
			</div>
			<div style="margin-left: 10px;width: 75%;">
				<p style="display: flex;align-items: center; ">
					{{ user
          }}<img src="../../static/VIP.svg" style="width: 1.3rem;height: 1.3rem;margin-left: 4px;" alt="" />
				</p>

				<p>
					{{
            userType == "1"
              ? "超级管理员"
              : userType == "2"
              ? "管理员"
              : "游客_" + user
          }}
				</p>
			</div>
			<div style="display: flex;justify-content: center;align-items: center;height: 100%;">
				<div>
					<img src="../../static/设置.svg" @click="showSet = true" style="width: 1.3rem;height: 1.3rem;"
						alt="" />
				</div>
				<div>
					<img src="../../static/退出.svg" style="width: 1.8rem;height:1.8rem;margin-left: 5px;" alt=""
						@click="anew" />
				</div>
			</div>
		</div>

		<!-- 筛选 留言 -->
		<div
			style="width: 100%;height: 30px;background-color: #fff;display: flex;align-items: center;justify-content: flex-end;padding: 10px;box-sizing: border-box;">
			<span @click="statisticalTableClick()" style="margin: 0 5px;color: #0b85db;">统计</span>
			<span @click="detailShiyongClick" style="margin: 0 5px;color: #0b85db;">备忘录</span>
			<span style="margin: 0 5px;" @click="shaiXuanFn">筛选</span>
		</div>

		<!-- 说明书 -->
		<cus-popup position="top" :zIndex="100" v-model="detailShiyong" :allowMarkClose="allowMarkClose"
			popup-wrap-custom="custom-pop">
			<view class="mark" style="height: 400px;">
				<h3 style="text-align: center;font-weight: 700;">备忘录<span style="margin-left: 10px; color: #0b85db;"
						@click="getleaveAmessage">刷新</span></h3>
				<ul style="height: 80%;width: 100%;overflow: scroll;">
					<li style="display: flex;margin: 10px 0;box-sizing: border-box;" v-for="item in leaveAmessageArray"
						:key="item._id">
						<div style="width: 3rem;height: 3rem;">
							<img src="../../static/012_快递员.svg" style="width: 100%;height: 100%;" alt="" />
						</div>
						<div style="width: 75%;">
							<p style="color: #999;">{{item.name ? item.name : item.phone}}</p>
							<div style="margin: 5px;">{{item.centent}}</div>
						</div>
						<div style="float: right;display: flex;align-items: center;" v-if="item.phone == user"
							@click="delLeaveAmessage(item)">X</div>
					</li>
				</ul>
				<div
					style="height: 10%;width: 100%;display: flex;border: 1px solid #999;margin-top: 10px;border-radius: 10px;box-sizing: border-box;">
					<input type="text" style="width: 80%;height: 100%;padding: 0 5px;box-sizing: border-box;"
						placeholder="我也说两句" v-model="leaveAmessage">
					<button style="width: 20%;height: 100%;border: none;background-color: #fff;margin-right: 2px;"
						@click="send">发送</button>
				</div>
			</view>
		</cus-popup>

		<!-- 筛选条件弹出框 -->
		<cus-popup position="top" :zIndex="100" v-model="shaiXuan" :allowMarkClose="allowMarkClose"
			popup-wrap-custom="custom-pop">
			<view class="mark">
				<div style="font-weight: 700;">查询地址</div>
				<div style="display: flex;align-items: center;justify-content: center;margin: 10px 0 ;">
					<input
						style="border-radius: 30px;border: 1px solid #999;width: 98%;height: 35px; font-size: 0.8rem; padding: 10px; box-sizing: border-box;"
						placeholder="请输入用户地址" type="text" v-model="seachFrom.userSite">
				</div>

				<div style="font-weight: 700;">查询牛奶品种</div>
				<!-- <div style="display: flex;align-items: center;justify-content: center;margin: 10px 0 ;">
					<input
						style="border-radius: 30px;border: 1px solid #999;width: 98%;height: 35px; font-size: 0.8rem; padding: 10px; box-sizing: border-box;"
						placeholder="请输入牛奶品种" type="text" v-model="seachFrom.typeName">
				</div> -->
				<view style="margin-top: 10px; ">
					<view class="uni-list">
						<checkbox-group @change="naiTypeChange" style="display: flex;flex-wrap: wrap;">
							<label class="uni-list-cell uni-list-cell-pd" style="display: flex;margin: 5px 10px;"
								v-for="item in naiArray" :key="item._id">
								<span>
									<checkbox :value="item.name" :checked="item.checked" />
								</span>
								<span>{{item.name}}</span>
							</label>
						</checkbox-group>
					</view>
				</view>

				<div style="font-weight: 700;">是否为app</div>
				<view style="margin-top: 10px; ">
					<view class="uni-list">
						<checkbox-group @change="checkboxChangeisApp" style="display: flex;flex-wrap: wrap;">
							<label class="uni-list-cell uni-list-cell-pd" style="display: flex;margin: 5px 10px;"
								v-for="item in isAppList" :key="item.value">
								<span>
									<checkbox :value="item.value" :checked="item.checked" />
								</span>
								<span>{{item.name}}</span>
							</label>
						</checkbox-group>
					</view>
				</view>

				<div><span style="font-weight: 700;">查询配送区域</span> <span style="margin-left: 10px;color: #0b85db;"
						@click="shaiXuanFn">刷新</span></div>
				<view style="margin-top: 10px; ">
					<view class="uni-list">
						<checkbox-group @change="checkboxChangeSite" style="display: flex;flex-wrap: wrap;">
							<label class="uni-list-cell uni-list-cell-pd" style="display: flex;margin: 5px 10px;"
								v-for="item in siteArray" :key="item._id">
								<span>
									<checkbox :value="item.name" :checked="item.checked" />
								</span>
								<span>{{item.name}}</span>
							</label>
						</checkbox-group>
					</view>
				</view>

				<div style="font-weight: 700;">查询配送时间</div>
				<view style="margin-top: 10px; ">
					<view class="uni-list">
						<checkbox-group @change="checkboxChange" style="display: flex;flex-wrap: wrap;">
							<label class="uni-list-cell uni-list-cell-pd" style="display: flex;margin: 5px 10px;"
								v-for="item in distributionTime" :key="item.value">
								<span>
									<checkbox :value="item.value" :checked="item.checked" />
								</span>
								<span>{{item.name}}</span>
							</label>
						</checkbox-group>
					</view>
				</view>
				<div style="display: flex;">
					<button style="font-size: 0.8rem;margin-top: 10px;width: 45%;" @click="empty()">清空</button>
					<button style="font-size: 0.8rem;margin-top: 10px;width: 45%;" type="primary"
						@click="seach()">查询</button>
				</div>
			</view>
		</cus-popup>

		<!-- 统计 -->
		<cus-popup position="top" :zIndex="100" v-model="statisticalTable" :allowMarkClose="allowMarkClose"
			popup-wrap-custom="custom-pop">
			<view class="mark" style="height: 400px;">
				<!-- 牛奶品种 -->
				<picker @change="bindPickerChange1" :value="index" :disabled="isDetail" :range="array"
					mode="multiSelector">
					<view class="picker" style="border: none;">
						<span>{{tongjiTime || "请选择查询年月"}}</span>
					</view>
				</picker>
				<ul>
					<li
						style="display: flex;justify-content: space-between;align-items: center;font-weight: 700;margin: 5px;">
						<p style="width: 50%;text-align: center;">名称</p>
						<p style="width: 50%;text-align: center;">月配送总数</p>
					</li>
					<li v-for="(item,index) in statisticalTableList" :key="index"
						style="display: flex;justify-content: space-between;align-items: center;margin: 5px;">
						<p style="width: 50%;text-align: center;">{{item.name}}
						<p>
						<p style="width: 50%;text-align: center;">{{item.count}}</p>
					</li>
				</ul>
			</view>
		</cus-popup>
		
		<!-- 点击序号出现 -->
		<cus-popup position="center" :zIndex="100" v-model="showAdd" :allowMarkClose="allowMarkClose"
			popup-wrap-custom="custom-pop">
			<view class="mark"
				style=" display: flex;flex-direction: column;align-items: center;justify-content: space-between;width: 100%;">
				<button @click="addIndex('top')" type="primary">在【上方】新增</button>
				<p style="font-size: 1rem;font-weight: 700; width: 100%;text-align: center;">
					{{ addClick.userSite }}
					<span
						style="margin-left:5px ; font-size:0.8rem;padding: 2px 5px; background:#eee;color:#999">
						{{ addClick.selected == 0 ? "全部" : "" }}
						{{ addClick.selected == 1 ? "工作日" : "" }}
						{{ addClick.selected == 2 ? "休息日" : "" }}
						{{ addClick.selected == 3 ? "单日" : "" }}
						{{ addClick.selected == 4 ? "双日" : "" }}
						{{ addClick.selected == 5 ? "自定义" : "" }}
					</span>
				</p>
				<button @click="addIndex('bottom')" type="primary">在【下方】新增</button>
			</view>
		</cus-popup>
		
		
		<!-- list -->
		<custom-tabs type="c1" :value="tabvalue" @change="changeIndex" style="height: 72%; overflow: hidden;" id="tabs"
			activeStyle="#1ba035">
			<custom-tab-pane :label="tabs.name" name="c1" v-for="tabs in tabs" :key="tabs.id">
				<div class="list" :style="{height:heightHome + 'px'}" style="overflow:scroll;">
					<div class="userInfo" v-for="(item, index) in tableArray" :key="item._openid"
						:class="item.flag ? '' : 'active'">
						<div class="left" @click="showAddFn(index)" style="position: relative;">
							<div v-if="item.pretreatment"
								style="width: 8px;height: 8px;border-radius: 50%;position: absolute;top: 2px;left: 2px;background-color: red;">
							</div>
							<span>{{ index + 1 }}</span>
						</div>
						
						<div class="right" style="width:80%;" @click="addOrEdit(index)">
							<p style="font-size: 1rem;font-weight: 700;" :class="item.flag ? '' : 'active'">
								{{ item.userSite }}
								<span
									style="margin-left:5px ; font-size:0.8rem;padding: 2px 5px; background:#eee;color:#999">
									{{ item.selected == 0 ? "全部" : "" }}
									{{ item.selected == 1 ? "工作日" : "" }}
									{{ item.selected == 2 ? "休息日" : "" }}
									{{ item.selected == 3 ? "单日" : "" }}
									{{ item.selected == 4 ? "双日" : "" }}
									{{ item.selected == 5 ? "自定义" : "" }}

								</span>
								<span v-if="item.isAPP == 1"
									style="margin-left:2px ; font-size:0.8rem;padding: 2px 5px; background:#eee;color:#999">
									App
								</span>
							</p>

							<p style="font-size: 0.8rem;color:#666">
								{{ item.startTime }} 至 {{ item.endTime }}
							</p>
							<span v-for="rows in item.kindArray"
								style="background-color: #1aa034;color: #fff;padding: 2px 5px;font-size: 0.7rem;margin: 0 5px;">
								{{ rows.name }}:{{ rows.number }}
							</span>
							<!-- <p class="enb"><span style="color: aqua;" @click="goDetail(index)"> 查看详情 </span> <span
										style="color:darkgoldenrod" @click="addOrEdit(index)"> 点击修改
									</span>
									<span style="color:red" @click="del(index)"> 点击删除 </span>
								</p> -->
						</div>
						<div style="width: 10%;display: flex;align-items: center;justify-content: center;">
							<img src="../../static/关闭2.svg" @click="del(index)" alt=""
								style="width: 1rem;height: 1rem;" />
						</div>
					</div>
				</div>
			</custom-tab-pane>
		</custom-tabs>

		<!-- 列表 -->

		<!-- 分页 -->
		<uni-pagination title="" show-icon="20" :total="total" @change="changePagination"
			style="background-color: #fff;" :current="page"></uni-pagination>
		<div class="footer">
			<button type="primary" @click="addOrEdit()">添加</button>
			<button type="default" @click="numberOff()">查看报数</button>
			<button type="primary" @click="paixu()">自动排序</button>
		</div>
	</div>
</template>

<script>
	// import uniPagination from "@/components/uni-pagination/uni-pagination.vue"
	import cusPopup from "@/components/cus-popup/popup.vue"
	export default {
		components: {
			cusPopup
		},
		data() {
			return {
				title: 'Hello',
				listArray: [],
				tableArray: [],
				user: "",
				userType: "",
				phone: "",
				showAddPhone: false,
				statisticsArr: [],
				statistics: false,
				sum: 0, //总数，
				// 添加牛奶品种
				showNai: false,
				// 设置
				showSet: false,
				sort: [],
				ssortShow: false,
				title: "",
				shaiXuan: false,
				allowMarkClose: true,
				// 显示添加弹出框
				showAdd: false,
				// 当前页
				page: 1,
				array: [
					["请选择年", 2022, 2023, 2024, 2025, 2026],
					["请选择月", 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]
				],
				index: 0,
				total: 0,
				// 点击序号 保存的数据
				addClick: {},
				// 查询条件
				seachFrom: {
					userSite: "", //用户名称
					selected: [], //派送日
					typeName: [],
					checkboxSite: [], // 已选地区
					isAPP: []
				},
				isAppList: [{
						name: "否",
						value: 0
					},
					{
						name: "是",
						value: 1
					}
				],
				jisuanZhuangtai: 2,
				// 筛选派送时间
				distributionTime: [{
					name: "全部",
					value: 0
				}, {
					name: "工作日",
					value: 1
				}, {
					name: "休息日",
					value: 2
				}, {
					name: "单日",
					value: 3
				}, {
					name: "双日",
					value: 4
				}, {
					name: "自定义",
					value: 5
				}],
				// 地区列表
				siteArray: [],
				showAddarea: false,
				naiArray: [], //牛奶品种
				// 使用说明
				detailShiyong: false,
				// 留言
				leaveAmessage: "",
				// 留言板信息
				leaveAmessageArray: [],
				tabvalue: "0",
				tabs: [{
						id: 1,
						name: "派送",
						value: 1
					},
					{
						id: 2,
						name: "排序",
						value: 2
					},
					{
						id: 3,
						name: "报数",
						value: 3
					}
				],
				heightHome: "",
				count: 0,
				statisticalTable: false,
				statisticalTableList: [],
				isDetail: false,
				tongjiTime: ""
			}
		},
		onLoad() {

			// this.updateSite()
			let that = this
			uni.getSystemInfo({
				success: function(res) { // res - 各种参数
					console.log(res.windowHeight); // 屏幕的宽度
					let info = uni.createSelectorQuery().select("#tabs"); // 获取某个元素
					info.boundingClientRect(function(data) { //data - 各种参数
						console.log("获取的高度", data.height) // 获取元素宽度
						that.heightHome = data.height * 0.87;
					}).exec()
				},
			})



			

			// 修改   doc要修改的id   update({data:{}})
			// const db = wx.cloud.database();
			// db.collection('painai').doc('2317770710').update({
			// 	data: {
			// 		userName: '测试02',
			// 	}
			// }).then(res => {
			// console.log(res , "res")
			// })

			// 查看			get()
			// const db = wx.cloud.database();
			// db.collection('painai').get().then(res => {
			// console.log(res.data , "res")
			// })

			// db.collection('painai').add({
			// 		data: {
			// 			_id:"479472394379",
			// 			endTime:"33123",
			// 			isMilkman:"33123",
			// 			kind:[{code:"3412312" , name:"111" , number:"1312312"}],
			// 			startTime:"33123",
			// 			userName:"33123",
			// 			userPhone:"33123",
			// 		}
			// 	})
			// 	.then(res => {
			// console.log(res)
			// 	})

		},

		onShow() {
			this.init()
			this.showAdd = false

		},
		methods: {
			// 排序
			changeList(val) {
				this.$showLoding("正在排序")
				this.tableArray = []
				console.log(this.user, val);
				uniCloud.callFunction({
					name: "pai_nai_del",
					data: {
						userId: this.user
					}
				}).then(res => {
					if (res.result.code != 200) {
						uni.showToast({
							title: '排序失败',
							//将值设置为 success 或者直接不用写icon这个参数
							icon: 'error',
							//显示持续时间为 2秒
							duration: 2000
						})
						return
					}
					val.forEach(item => {
						delete item._id
					})
					uniCloud.callFunction({
						name: "pai_nai_add",
						data: val
					}).then(res => {
						this.$hideLoading()
						uni.showToast({
							title: '排序成功',
							//将值设置为 success 或者直接不用写icon这个参数
							icon: 'none',
							//显示持续时间为 2秒
							duration: 2000
						})
						this.listArray = val
						this.tableArray = val

					}).catch(() => {
						this.$hideLoading()
						uni.showToast({
							title: '排序失败',
							//将值设置为 success 或者直接不用写icon这个参数
							icon: 'error',
							//显示持续时间为 2秒
							duration: 2000
						})
					})
				}).catch(() => {
					this.$hideLoading()
					uni.showToast({
						title: '排序失败',
						//将值设置为 success 或者直接不用写icon这个参数
						icon: 'error',
						//显示持续时间为 2秒
						duration: 2000
					})
					this.getTabArray(2)
				})

			},

			// 初始化
			init(index) {
				let coumt = 0
				// 获取本地存储
				let phone = uni.getStorageSync("phone");
				console.log(phone);
				// 获取用户手机号 , 查看手机号是否存在
				if (phone) {
					this.user = phone //保存手机号
					uniCloud.callFunction({
						name: "userPhone",
						data: {
							phone: phone || ""
						}
					}).then(res => {
						console.log("res", res);
						if (res.result.data.length == 0) {
							uni.redirectTo({
								url: "/pages/home/index"
							})
						} else {
							this.userType = res.result.data[0].userType
							this.getTabArray(this.tabvalue)
						}

					}).catch(() => {

						if (phone) {
							this.getTabArray(this.tabvalue)
						} else {
							uni.showToast({
								title: '获取不到手机',
								//将值设置为 success 或者直接不用写icon这个参数
								//显示持续时间为 2秒
								icon: 'none',
								duration: 2000
							})
						}
					})
				} else {
					uni.redirectTo({
						url: "/pages/home/index"
					})
				}

			},

			// 获取用户信息列表  默认当天
			getTabArray(number = 0) {
				this.$showLoding("加载中...")
				let dateTime = new Date()
				let dateTimeJSON =
					`${dateTime.getFullYear()}-${dateTime.getMonth() + 1 < 10 ? '0' + (dateTime.getMonth() + 1) :  (dateTime.getMonth() + 1)}-${dateTime.getDate()}`
				uniCloud.callFunction({
					name: "pai_nai_List",
					data: {
						userId: this.user,
						number: number,
						dateTime: dateTimeJSON,
						limit: 10, //分页
						pageSize: this.page, //分页
						seachFrom: this.seachFrom //搜索条件
					}
				}).then(res => {
					console.log(res);
					this.tableArray = res.result.data
					this.tabvalue = number
					this.total = res.result.total
					this.$hideLoading()
				}).catch(() => {
					console.log("失败u");
				})
			},

			// tabs发生变化
			changeIndex(val) {
				console.log(val);
				this.tabs.forEach((item, index) => {
					if (item.name == val.label) {
						this.getTabArray(index)
					}
				})
			},

			// 点击筛选按钮
			shaiXuanFn() {
				// 发送请求获取筛选数据
				this.shaiXuan = true
				uniCloud.callFunction({
					name: "nai"
				}).then(res => {
					this.naiArray = res.result.data
				})
				let phone = uni.getStorageSync("phone");
				// 获取配送区域
				uniCloud.callFunction({
					name: "area",
					data: {
						phone: phone
					}
				}).then(res => {
					// 保存数据
					this.siteArray = res.result.data
				})
			},

			// 搜索
			seach() {
				this.page = 1
				console.log(this.seachFrom);
				this.shaiXuan = false
				this.getTabArray()
			},

			// 清空
			empty() {
				this.seachFrom = {
					userSite: "", //用户名称
					selected: [], //派送日
					typeName: [],
					checkboxSite: [],
					isAPP: []
				}
				this.distributionTime.forEach(item => {
					item.checked = false
				})
				this.siteArray.forEach(item => {
					item.checked = false
				})
				this.naiArray.forEach(item => {
					item.checked = false
				})
				this.isAppList.forEach(item => {
					item.checked = false
				})
				this.shaiXuan = false
				this.getTabArray()
			},

			jisuan(number = 0, show = false) {
				this.getTabArray(number)
				let dateTime = new Date()
				let dateTimeJSON =
					`${dateTime.getFullYear()}-${dateTime.getMonth() + 1 < 10 ? '0' + (dateTime.getMonth() + 1) :  (dateTime.getMonth() + 1)}-${dateTime.getDate()}`
				uniCloud.callFunction({
					name: "pai_nai",
					data: {
						userId: this.user,
						number: number,
						dateTime: dateTimeJSON
					}
				}).then(res => {
					this.listArray = res.result.data
					if (number == 1) {
						this.paixuJS(show)
						uni.showToast({
							title: '列表切换--排序',
							//将值设置为 success 或者直接不用写icon这个参数
							//显示持续时间为 2秒
							icon: 'none',
							duration: 2000
						})
					} else {
						this.numberOffJS(show)
						uni.showToast({
							title: '列表切换--报数',
							//将值设置为 success 或者直接不用写icon这个参数
							//显示持续时间为 2秒
							icon: 'none',
							duration: 2000
						})
					}
				}).catch(() => {
					uni.showToast({
						title: 'axios请求失败1-1',
						//将值设置为 success 或者直接不用写icon这个参数
						//显示持续时间为 2秒
						icon: 'none',
						duration: 2000
					})
				})
			},

			// 点击统计按钮
			statisticalTableClick() {
				this.statisticalTable = true
				// 发送请求
				uniCloud.callFunction({
					name: "statistics",
					data: {
						userId: this.user,
						yearM: this.tongjiTime
					}
				}).then(res => {
					console.log(res);
					this.statisticalTableList = res.result.data
				}).catch(() => {
					console.log("失败");
				})
			},

			bindPickerChange1(val) {
				console.log(val);
				if (val.detail.value[0] == 0 || val.detail.value[1] == 0) {
					return
				} else {
					this.tongjiTime = this.array[0][val.detail.value[0]] + "-" + this.array[1][val.detail.value[1]]
					console.log(this.tongjiTime);
					this.statisticalTableClick()
				}
			},

			// 添加或修改
			addOrEdit(index) {
				// console.log(index);
				if (index >= 0) {
					let obj = this.tableArray[index]
					// console.log(obj);
					uni.navigateTo({
						url: `/pages/add/index?isAdd=${obj._id}`
					});
				} else {
					uni.navigateTo({
						url: `/pages/add/index?isAdd=undefind`
					});
				}

			},
			// 点击去往详情页
			goDetail(index) {
				let obj = this.tableArray[index]
				console.log(obj);
				uni.navigateTo({
					url: `/pages/add/index?isAdd=${obj._id}&isDetail=true`
				});
			},
			// 删除数据
			del(index) {
				let _flag = this
				let obj = this.tableArray[index]

				const db = wx.cloud.database();
				uni.showModal({
					title: '提示',
					content: '确认删除该条信息吗？',
					success: function(res) {
						if (res.confirm) {
							uniCloud.callFunction({
								name: "pai_nai_del",
								data: {
									_id: obj._id
								}
							}).then(res => {
								_flag.init("删除成功")
							})
						} else {
							// 执行取消后的操作
							uni.showToast({
								title: '取消删除成功',
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'success',
								//显示持续时间为 2秒
								duration: 2000
							})
						}
					}
				})
			},

			//发送
			send() {
				// console.log(this.leaveAmessage);
				uniCloud.callFunction({
					name: "leaveAmessage_add",
					data: {
						phone: this.user,
						centent: this.leaveAmessage,
						// time:new Date()
					}
				}).then(res => {
					// console.log(res);
					uni.showToast({
						title: '留言成功',
						//将值设置为 success 或者直接不用写icon这个参数
						//显示持续时间为 2秒
						duration: 2000
					})
					this.getleaveAmessage()
				})
				this.leaveAmessage = ""
			},

			// 删除评论
			delLeaveAmessage(item) {
				// console.log(item);
				this.$showLoding("删除中...")
				uniCloud.callFunction({
					name: "leaveAmessage_del",
					data: {
						_id: item._id
					}
				}).then(res => {
					// console.log(res);
					if (res.result.code == 200) {
						this.getleaveAmessage()
						this.$hideLoading()
					}
				})
			},

			// 点击留言按钮
			detailShiyongClick() {
				this.detailShiyong = true
				// 获取留言板信息
				this.getleaveAmessage()
			},

			// 获取留言信息
			getleaveAmessage() {
				uniCloud.callFunction({
					name: "leaveAmessage",
					data: {
						phone: this.user
					}
				}).then(res => {
					this.leaveAmessageArray = res.result.data
				})
			},

			// 点击序号
			showAddFn(index) {
				// console.log(this.tableArray[index]);
				this.showAdd = true
				this.addClick = this.tableArray[index] //当前点击数据
			},

			// 插入
			addIndex(location) {
				let url = ""
				// 在上方插入
				if (location == "top") {
					url = `/pages/add/index?isAdd=undefind&location=${this.addClick._id}&index=0`
				} else if (location == "bottom") {
					// 在下方插入
					url = `/pages/add/index?isAdd=undefind&location=${this.addClick._id}&index=1`
				}
				uni.navigateTo({
					url: url
				});
			},

			// 添加管理
			addAdmin() {
				if (isNaN(this.phone * 1)) {
					uni.showToast({
						title: '请输入纯数字',
						//将值设置为 success 或者直接不用写icon这个参数
						icon: 'error',
						//显示持续时间为 2秒
						duration: 2000
					})
					return
				}
				if (this.phone <= 0 || this.phone.length < 11) {
					uni.showToast({
						title: '请输入11位数纯数字',
						//将值设置为 success 或者直接不用写icon这个参数
						icon: 'error',
						//显示持续时间为 2秒
						duration: 2000
					})
					return
				}
				uniCloud.callFunction({
					name: "userPhone", //参数是云函数的名 会自动找这个云函数
					data: {
						phone: this.phone
					}
				}).then((res) => {
					// res
					if (res.result.code == 200) {
						if (res.result.data.length != 0) {
							uni.showToast({
								title: '该用户已是管理员',
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'error',
								//显示持续时间为 2秒
								duration: 2000
							})
						} else {
							uniCloud.callFunction({
								name: "userPhone_add", //参数是云函数的名 会自动找这个云函数
								data: {
									phone: this.phone
								}
							}).then(res => {
								// console.log(res);
								uni.showToast({
									title: res.result.message,
									//将值设置为 success 或者直接不用写icon这个参数
									icon: 'success',
									//显示持续时间为 2秒
									duration: 2000
								})
								this.showAddPhone = false
								this.phone = ''
							})
						}

					}
				})
			},
			// 去往会员列表页面
			goAdmin(name) {
				uni.navigateTo({
					url: `/pages/adminList/index?type=${name}`
				});
			},

			// 筛选牛奶名称发生变化
			naiTypeChange(val) {
				this.seachFrom.typeName = val.detail.value
				// console.log(val);
			},

			// 筛选是否仅看app
			checkboxChangeisApp(val) {
				this.seachFrom.isAPP = val.detail.value
			},
			// 添加地区
			addArea() {

				// 查询地区
				uniCloud.callFunction({
					name: "area",
					data: {
						name: this.phone,
						phone: this.user
					}
				}).then(res => {
					// console.log(res);
					if (res.result.data.length == 0) {
						uniCloud.callFunction({
							name: "area_add",
							data: {
								name: this.phone,
								phone: this.user
							}
						}).then(res => {
							if (res.result.code == 200) {
								uni.showToast({
									title: '添加地区成功',
									//将值设置为 success 或者直接不用写icon这个参数
									//显示持续时间为 2秒
									duration: 2000
								})
								this.showAddarea = false
							}
						})
					} else {
						uni.showToast({
							title: '该地区已存在',
							icon: "error",
							//将值设置为 success 或者直接不用写icon这个参数
							//显示持续时间为 2秒
							duration: 2000
						})
					}
				})

			},

			// 重新登录
			anew() {
				uni.redirectTo({
					url: "/pages/home/index"
				})
			},
			// 查看报数
			numberOff() {
				this.jisuanZhuangtai = 2
				this.$showLoding("计算中")
				this.jisuan(this.jisuanZhuangtai, true)

			},

			numberOffJS(show) {
				this.sum = 0
				this.statistics = show

				this.statisticsArr = []
				let accordWith = []; //符合条件的数据
				let ing = new Date() //当前时间
				let ingYears = ing.getFullYear()
				let ingMonth = ing.getMonth() + 1 //当前月
				let ingGetDate = ing.getDate() + 2 //后天日
				let ingTime =
					`${ingYears}-${ingMonth < 10 ? "0" + ingMonth: ingMonth }-${ingGetDate < 10 ? "0" + ingGetDate : ingGetDate}`
				let timestamp = new Date(ingTime).getTime() //当前时间戳
				let ingGetDay = new Date(ingTime).getDay() //当前星期
				// let data = new Date('2023-09-02')
				// console.log(data.getTime());
				let aaa = new Date(ingTime).getDate()
				// console.log(aaa, "时间", ingTime);
				this.listArray.forEach(item => {
					// 将时间转换为时间戳
					let startTimestamp = new Date(item.startTime).getTime() // 开始时间时间戳
					let endTimestamp = new Date(item.endTime).getTime() // 结束时间时间戳
					// console.log(timestamp >= startTimestamp && timestamp <= endTimestamp  ); //大于等于开始时间   小于等于结束时间
					if (timestamp >= startTimestamp && timestamp < endTimestamp) { //判断区间
						// if (item.flag) {}
						if (item.isAPP == 1) {
							return
						}
						if (item.selected == 0) {
							accordWith.push(item) //获取符合条件的数据
						} else if (item.selected == 1) {
							if (ingGetDay == 0 || ingGetDay == 6) {} else {
								accordWith.push(item) //获取符合条件的数据
							}
						} else if (item.selected == 2) {
							if (ingGetDay == 0 || ingGetDay == 6) {
								accordWith.push(item) //获取符合条件的数据
							}
						} else if (item.selected == 3) {
							if (ingGetDate % 2 != 0) {
								accordWith.push(item) //获取符合条件的数据
							}
						} else if (item.selected == 4) {
							if (ingGetDate % 2 == 0) {
								accordWith.push(item) //获取符合条件的数据
							}
						} else if (item.selected == 5) {
							// console.log(item.checkboxArray.indexOf(ingGetDay.toString()), item.checkboxArray, item
							// 	.userSite);
							if (item.checkboxArray.indexOf(ingGetDay.toString()) != "-1") {
								accordWith.push(item) //获取符合条件的数据
							}
						}
					}
				})

				let statistics = []
				accordWith.forEach(item => {
					// debugger
					item.kindArray.forEach(itmes => {
						statistics.push({
							name: itmes.name,
							number: itmes.number
						})
					})
				})
				this.sort = statistics
				// console.log(statistics, "statistics");
				let newArray = []
				// console.log(statistics);
				statistics.forEach(item => {
					let flag = true
					let obj = {}
					// newArray.length == 0 ? newArray.push(item) : false
					if (newArray.length == 0) {
						newArray.push(item)
						// return;
					} else {
						newArray.forEach((row, index) => {
							if (item.name == row.name) {
								row.number += item.number
								flag = false
							}
							if (flag) {
								obj = item
							}
							// 判断是否为最后一次循环
							// console.log(newArray.length - 1 == index , "是否最后一次");
							// if ((newArray.length - 1) == index) {
							// console.log(flag , "进入最后一次了");
							// 	obj = item
							// }
						})
					}

					if (flag && obj.name) {
						// console.log(obj);
						newArray.push(obj)
					}
					this.sum += item.number
				})
				// console.log(newArray);


				this.statisticsArr = newArray
			},

			// 先执行排序获取排序数据
			paixu() {
				this.jisuanZhuangtai = 1
				this.$showLoding("计算中")
				this.jisuan(this.jisuanZhuangtai, true)
			},
			//再执行获取排序列表
			paixuJS(show) {
				this.ssortShow = show
				this.count = 0
				let accordWith = []; //符合条件的数据
				let ing = new Date() //当前时间
				let ingYears = ing.getFullYear()
				let ingMonth = ing.getMonth() + 1 //当前月
				let ingGetDate = ing.getDate() + 1 //当前日
				let ingGetDay = ing.getDay() + 1 //当前星期
				if (ingGetDay == 7) {
					ingGetDay = 0
				}
				let ingTime =
					`${ingYears}-${ingMonth < 10 ? "0" + ingMonth : ingMonth}-${ingGetDate < 10 ? "0" + ingGetDate : ingGetDate}`
				let timestamp = new Date(ingTime).getTime() //当前时间戳  明天
				// console.log(ingTime);
				// let data = new Date('2023-09-02')
				// console.log(data.getTime());
				this.listArray.forEach(item => {
					// 将时间转换为时间戳
					let startTimestamp = new Date(item.startTime).getTime() // 开始时间时间戳
					let endTimestamp = new Date(item.endTime).getTime() // 结束时间时间戳
					// console.log(timestamp >= startTimestamp && timestamp <= endTimestamp  ); //大于等于开始时间   小于等于结束时间
					if (timestamp >= startTimestamp && timestamp < endTimestamp) { //判断区间

						if (item.selected == 0) {
							accordWith.push(item) //获取符合条件的数据
						} else if (item.selected == 1) {
							// 休息日
							if (ingGetDay == 0 || ingGetDay == 6) {} else {
								accordWith.push(item) //获取符合条件的数据
							}
						} else if (item.selected == 2) {
							if (ingGetDay == 0 || ingGetDay == 6) {
								accordWith.push(item) //获取符合条件的数据
							}
						} else if (item.selected == 3) {
							console.log(ingGetDay % 2);
							if (ingGetDay % 2 != 0) {
								accordWith.push(item) //获取符合条件的数据
							}
						} else if (item.selected == 4) {
							if (ingGetDay % 2 == 0) {
								accordWith.push(item) //获取符合条件的数据
							}
						} else if (item.selected == 5) {
							console.log(item.checkboxArray.indexOf(ingGetDay.toString()), item
								.checkboxArray, item
								.userSite);
							if (item.checkboxArray.indexOf(ingGetDay.toString()) != "-1") {
								accordWith.push(item) //获取符合条件的数据
							}
						}

					}
				})

				let statistics = []
				accordWith.forEach(item => {
					// debugger
					item.kindArray.forEach(itmes => {
						this.count += itmes.number
						statistics.push({
							name: itmes.name,
							number: itmes.number
						})
					})
				})


				this.sort = statistics
			},

			// 急速快排
			quickness() {
				let stortDate = {} //存储上一个
				let stortIndex = 0 //存储上一个的索引
				let newArray = []
				this.sort.forEach((item, index) => {
					// 第一次进来没值
					if (!stortDate.name) {
						newArray.push(item)
						stortIndex = newArray.length - 1
					} else {
						// 判断当前的name是否与上一个的name相同
						if (item.name == stortDate.name) {
							// console.log(newArray[stortIndex].number);
							// console.log(item.number);
							// console.log(newArray[stortIndex].number , item.number , newArray[stortIndex].number = newArray[stortIndex].number +  item.number);
							// 将当前的number加到上一个的number里面、
							newArray[stortIndex].number = newArray[stortIndex].number + item.number
						} else {
							newArray.push(item)
							stortIndex = newArray.length - 1 //保存最后一次
						}
					}
					stortDate = item

				})

				this.sort = newArray
			},

			// 添加牛奶品种
			addNai() {
				uniCloud.callFunction({
					name: "nai",
					data: {
						name: this.phone
					}
				}).then(res1 => {
					// console.log(res1.result.data.length, "res");
					if (res1.result.data.length != 0) {
						uni.showToast({
							title: '已添加该品种',
							//将值设置为 success 或者直接不用写icon这个参数
							icon: 'error',
							//显示持续时间为 2秒
							duration: 2000
						})
					} else {
						uniCloud.callFunction({
							name: "nai_add",
							data: {
								name: this.phone
							}
						}).then(res => {
							// console.log(res, "res");
							uni.showToast({
								title: '添加成功',
								//将值设置为 success 或者直接不用写icon这个参数
								icon: 'success',
								//显示持续时间为 2秒
								duration: 2000
							})
							this.showNai = false
							this.phone = ''
						})

					}
				})

			},

			changePagination(val) {
				console.log(val);
				this.page = val.current
				this.getTabArray(this.tabvalue)
			},

			// 筛选配送日
			checkboxChange(val) {
				console.log(val);
				this.seachFrom.selected = val.detail.value
			},
			checkboxChangeSite(val) {
				console.log(val);
				this.seachFrom.checkboxSite = val.detail.value
			}
		},


	}
</script>

<style>
	.maxBox {
		width: 100%;
		height: 100%;
		border-radius: 5px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		overflow: hidden;
	}

	.list {
		width: 100%;
		overflow: scroll;
		/* padding: 0 10px; */
		background-color: #f1f1f1;
		box-sizing: border-box;
	}

	.user {
		background-color: #fff;
		width: 100%;
		height: 10%;
		display: flex;
		padding: 10px;
		box-sizing: border-box;
	}

	.userInfo {
		width: 100%;
		padding: 10px;
		box-sizing: border-box;
		background-color: #fff;
		box-shadow: 0 0 4px 0px rgba(0, 0, 0, 0.4);
		margin: 10px 0;
		border-radius: 5px;
		display: flex;
	}

	.userInfo .left {
		display: flex;
		align-items: center;
		justify-content: center;
		/* padding: 0 10px; */
		width: 10%;
		font-size: 1.2rem;
		border-right: 2px solid #f1f1f1;
	}

	.userInfo .right {
		margin-left: 10px;
	}

	.userInfo p {
		width: 100%;
		color: #333;
	}

	.userInfo p span {
		margin-right: 10px;
		margin-top: 10px;
	}

	.footer {
		width: 100%;
		height: 10%;
		background-color: #fff;
		display: flex;
		overflow: hidden;
		align-items: center;
	}

	/* .footer button {
	} */

	/* 添加账号权限 */
	.jia {
		width: 50px;
		height: 50px;
		border-radius: 50%;
		background-color: #1aa034;
		color: #fff;
		font-size: 1.5rem;
		position: absolute;
		bottom: 30%;
		right: 5px;
		z-index: 999;
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.zhezhao {
		position: absolute;
		top: 0;
		z-index: 9999999;
		left: 0;
		width: 100%;
		height: 100%;
		background-color: rgba(0, 0, 0, 0.4);
	}

	.jiaBox {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		width: 90%;
		height: 50%;
		overflow: scroll;
		border-radius: 30px;
		z-index: 99999999;
		background-color: #fff;
		transition: all 0.4s;
		display: flex;
		align-items: center;
		justify-content: center;
		flex-direction: column;
	}

	.jiaBox input {
		width: 80%;
		height: 40px;
		border-radius: 10px;
		padding: 10px;
		box-sizing: border-box;
		background-color: #f1f1f1;
	}

	.jiaBox button {
		width: 70%;
		margin-top: 60px;
		color: #fff;
		background-color: #1aa034;
	}

	.jiaBox .painai {
		width: 100%;
		height: 100%;
		overflow: scroll;
		padding: 10px 0px;
		box-sizing: border-box;
	}

	.jiaBox .painai li {
		width: 100%;
		height: 40px;
		display: flex;
		justify-content: space-between;
		align-items: center;
		border-bottom: 1px solid #666;
		padding: 10px;
		box-sizing: border-box;
	}

	.jiaBox .painai li span {
		display: inline-block;
		width: 45%;
		text-align: center;
	}

	.active {
		color: red !important;
		text-decoration: line-through;
	}

	.setArr {
		width: 80%;
		height: 50%;
		background-color: #fff;
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -50%);
		z-index: 9999999;
		border-radius: 10px;
		padding: 10px;
		box-sizing: border-box;
		overflow: scroll;
	}

	.setArr button {
		height: 40px;
		display: flex;
		align-items: center;
		justify-content: center;
		margin: 10px 0;
	}

	/* //scoped 在当前页生效 不影响子组件 */
	.drag-item {
		width: 100%;
		height: 100%;
		display: flex;
		align-items: center;
	}

	.item-icon {
		position: absolute;
		left: 10px;
		display: inline-block;
		line-height: 70px;
		color: #FF5500;
	}

	.mark {
		height: 300px;
		overflow: scroll;
		box-sizing: border-box;
	}
</style>